// 第一个部署
// 1、SR、SSR、UR 限制了发行数量 (部署时完成)
// 2、需要设置一个minter, bindBox 盲盒合约，用于开盲盒后铸造 (部署后完成) setMinter 方法
// gas:  0.06BNB
// address: 0x9cB811C7E14c4b7743b580BA607cDD6793f1371F
const { BigNumber } = require('ethers');

async function main() {
    // 配置
    const nftName = "SpaceTime Dog";
    const nftSymbol = "SDOG";
    const nftUrl = "https://nftswap-hm.oss-cn-chengdu.aliyuncs.com/metadata/";
    const SRtotalSupply = 6000;
    const SSRTotalSupply = 3000;
    const URTotalSupply = 1000;

    const token_limit = 10000;  //NFT 发行数量

    const feeToken = "0x55d398326f99059fF775485246999027B3197955"; // 支付token BRC20-USDT 地址
    const NFTSwapAddress = "0xba58F107fD3e82D014BEed3Ca8D82f4c77a333bE"; // NFTSWAP 合约地址
    const rarities = [1,2,3]; // 稀有度枚举
    const lpAmounts = [1,3,6]; // 稀有度份额

    const meatdataUrl = "https://nftswap-hm.oss-cn-chengdu.aliyuncs.com/mysteryBox/metadata/";  // 盲盒 url

    const _feeReceiver = "0x94AaD901D8418E61F3beC7cC331072317A35511f";  // 收益接收者

    //1、部署NFTDog ： 0x025E2F9FfafA019E4aA42234fdE4DDaFBFC096dE
    const nftStruggleDog = await ethers.getContractFactory("StruggleDog");
    const instanceNftStruggleDog = await nftStruggleDog.deploy(SRtotalSupply,SSRTotalSupply, URTotalSupply, nftName, nftSymbol, nftUrl);
    await instanceNftStruggleDog.deployed();
    console.log("NftStruggleDog deployed to:", instanceNftStruggleDog.address);

    //2、部署彩票合约
    const Lottery = await ethers.getContractFactory("Lottery");
    const instanceLottery = await upgrades.deployProxy(Lottery, [token_limit], {initializer:'__Lottery_init'});
    await instanceLottery.deployed();
    console.log("Lottery deployed to:", instanceLottery.address);

    //3、部署质押合约
    const LpToken = await ethers.getContractFactory("LpToken");
    const instanceLpToken = await upgrades.deployProxy(LpToken, [feeToken,instanceNftStruggleDog.address,NFTSwapAddress,rarities, lpAmounts], {initializer:'__LpToken_init'});
    await instanceLpToken.deployed();
    console.log("LpToken deployed to:", instanceLpToken.address);

    //4、部署盲盒合约
    const BlindBox = await ethers.getContractFactory("BlindBox");
    const instanceBlindBox = await upgrades.deployProxy(BlindBox, [meatdataUrl,instanceNftStruggleDog.address,instanceLottery.address], {initializer:'__BlindBox_init'});
    await instanceBlindBox.deployed();
    console.log("BlindBox deployed to:", instanceBlindBox.address);

    //5、部署盲盒售卖合约
    const BBoxSwap = await ethers.getContractFactory("BBoxSwap");
    const instance = await upgrades.deployProxy(BBoxSwap, [_feeReceiver, feeToken], {initializer:'__BBoxSwap_init'});
    await instance.deployed();
    console.log("BBoxSwap deployed to:", instance.address);
}

main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error);
        process.exit(1);
    });

// 部署完成后，还有几个合约交互设置，整个系统才能正常运行：
// 1、操作 {StruggleDog} 合约 【setMinter】 方法，设置 bindBox 合约账户为 铸造者，盲盒合约才能在开启后铸造 奋斗狗NFT。
// 2、操作 {Lottery} 合约 【setBindBox】 方法，设置 bindBox 合约账户才能调用 该合约随机方法。
// 3、操作 {NFTSwap} 合约 【setDividend】方法，设置 分红比例，分红收益接收地址为LpToken 合约。